package net.crowdloud.server.DatabaseAccess.tags;

import javax.jdo.PersistenceManager;

import net.crowdloud.client.tags.TagsDatabaseServerCalls;
import net.crowdloud.server.DatabaseAccess.DatabaseConnection;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * 
 * @Architecture
 */
@SuppressWarnings("serial")
public class TagsDatabaseImplementation extends RemoteServiceServlet implements
		TagsDatabaseServerCalls {

	@Override
	public net.crowdloud.shared.entities.Tags getTags() {

		PersistenceManager persistenceManager = DatabaseConnection.connect();

		net.crowdloud.shared.entities.Tags tags = GetTags.get(persistenceManager);

		persistenceManager.close();

		return tags;
	}

	@Override
	public void addTags(net.crowdloud.shared.entities.Tags tags) {

		tags.setTagsList("Java, JavaScript, GWT, Logo, Amazon Cloud, EC2,"
				+ " GAE, Eclipse, PHP, Ruby, Web Design, Tester,"
				+ " Customer Development, Business Development, Marketing");

		PersistenceManager persistenceManager = DatabaseConnection.connect();

		SaveTags.addNew(persistenceManager, tags.getTagsList());

		persistenceManager.close();
	}

	@Override
	public void updateTags(net.crowdloud.shared.entities.Tags tags) {

		PersistenceManager persistenceManager = DatabaseConnection.connect();

		SaveTags.update(persistenceManager, tags);

		persistenceManager.close();
	}
}
